﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PortChat
{
    //frame analyzer
    class FrameAnalyzer
    {
        //frame number
        private char[] charArrFrameNumber = new char[5];
        //handshaking flag
        private char[] charArrHandshakingFlag = new char[1];
        //check word flag
        private char[] charArrCheckWordFlag = new char[1];
        //COM port name
        private char[] charArrComPortName = new char[4];
        //payload
        private char[] charArrPayload = new char[8];


        //FrameNumber| Quittung| checkWord | COMName| Code
        //10000      |      0  |    0      | 0001   | 00000000 
        public void analyzeFrame(String strFrameP)
        {
            //Boolean bStartFlagValid = strFrameP.StartsWith("01111110");
            //Boolean bEndFlagValid = strFrameP.EndsWith("01111110");

            //FrameNumber | QuittungsFlag | PayLoad
            //10000    |      0        | <COM1>: 000
            strFrameP.CopyTo(0, charArrFrameNumber, 0, 5);
            strFrameP.CopyTo(5, charArrHandshakingFlag, 0, 1);
            strFrameP.CopyTo(6, charArrCheckWordFlag, 0, 1);
            strFrameP.CopyTo(7, charArrComPortName, 0, 4);
            strFrameP.CopyTo(11, charArrPayload, 0, 8);
                                  
        }

        public char[] getPayload()
        {
            return charArrPayload;
        }

        public char[] getHandshakingFlag()
        {
            return charArrHandshakingFlag;
        }
        public char[] getCheckWordFlag()
        {
            return charArrCheckWordFlag;
        }

        public char[] getFrameNumber()
        {
            return charArrFrameNumber;
        }
        public char[] getComPortName()
        {
            return charArrComPortName;
        }        
    }
}
